package app.kotlin_1.utils

import android.support.v4.view.ViewPager
import android.util.Log
import android.view.View

/**
 * Created by 刘智强 on 2017/9/21.
 */

class GalleyTransFormer : ViewPager.PageTransformer {
    companion object {
        private val MAX_SCALE = 1.2f //中间那张图片的缩放比例
        private val MIN_SCALE = 0.8f//0.85f 两边小图的缩放比例
    }

    /**
     *
     */
    override fun transformPage(page: View, position: Float) {
//
//        if (position <= 1) {
//            val scaleFactor = MIN_SCALE + (1 - Math.abs(position)) * (MAX_SCALE - MIN_SCALE)
//            Log.e("!!", scaleFactor.toString() + "")
//            page.scaleX = scaleFactor
//            if (position > 0) {
//                page.translationX = -scaleFactor * 2
//            } else if (position < 0) {
//                page.translationX = scaleFactor * 2
//            }
//            page.scaleY = scaleFactor
//        } else {
//
//            page.scaleX = MIN_SCALE
//            page.scaleY = MIN_SCALE
//        }
        when {
            position <=-1 -> { /* [-Infinity,-1)*/
                /*页面已经在屏幕左侧且不可视*/
            }
            position <= 0 -> { /* [-1,0]*/
                /*页面从左侧进入或者向左侧滑出的状态*/
                page.cameraDistance = 10000F
                page.pivotX = page.measuredWidth.toFloat()
                page.pivotY = (page.measuredHeight )*0.5f
                page.rotationY = 90*position
            }
            position <= 1 -> {/* (0,1]*/
                /*页面从右侧进入或者向右侧滑出的状态*/
                page.cameraDistance = 10000F
                page.pivotX = 0F
                page.pivotY =(page.width) *0.5f
                page.rotationY = 90*position
            }
            position >1 -> {
                /*页面已经在屏幕右侧且不可视*/
            }
        }
    }


}
